home *** CD-ROM | disk | FTP | other *** search
- ;This function calculates the centroid and the moment of inertia
- ; for a profile. The profile should be "selected" immediately
- ; before invoking this routine. The function creates creates a
- ; layer named "Moment", creates a red point at the centroid
- ; and then prints the x and y moment of inertia values.
- ; The function averages exploded cross hatching to calculate the
- ; centroid and integrates each points' delta from the centroid to
- ; determine the moment. (see Cadence Vol.1 No.3, pg 51)
- ;
- ;================================================================
- ; CHAZ HENRY NORTH CAROLINA STATE UNIVERSITY, RALEIGH, NC
- ;================================================================
- ; 12-12-86 SIEMENS ENERGY AND AUTOMATION, RALEIGH, NC
- ;================================================================
-
- (defun moment ( / l xcord ycord temp momentx momenty cnt oldlay centroidx
- centroiidy scale ss e scalesqterm cellsize)
- (if (ssget "p")
- (progn
- (setq cnt 0 centroidx 0 centroidy 0 oldlay (getvar "CLAYER"))
- (setq scale (* (getvar "VIEWSIZE") 0.4))
- (command "LAYER" "m" "moment" "c" "red" "moment" "")
- (command "HATCH" "*DOTS" scale "45" "p" "")
- (command "LAYER" "off" "*" "n" "")
- (setq ss (ssget "W" (getvar "LIMMAX") (getvar "LIMMIN")))
-
- (setq l (sslength ss))
- (princ "calculating centroid.....")
- (while (< cnt l)
- (progn
- (setq e (entget (ssname ss cnt)))
- (setq centroidx (+ centroidx (car (cdr (assoc 10 e)))))
- (setq centroidy (+ centroidy (nth 2 (assoc 10 e))))
- (setq cnt (1+ cnt))))
-
- (setq centroidx (/ centroidx cnt)
- centroidy (/ centroidy cnt))
- (princ "done")
- (terpri)
-
- (princ "calculating moment of inertia.....")
-
- (setq cnt 0
- cellsize (* (/ scale 16) (/ scale 16))
- momentx 0
- momenty 0
- cellsqterm (/ (* cellsize cellsize) 12))
-
- (while (< cnt l)
- (progn
- (setq e (entget (ssname ss cnt)))
- (setq xcord (car (cdr (setq temp (assoc 10 e)))))
- (setq ycord (nth 2 temp))
- (setq momentx (+ momentx
- cellsqterm
- (* cellsize (* (setq temp (- centroidx xcord)) temp))))
- (setq momenty (+ momenty
- cellsqterm
- (* cellsize (* (setq temp (- centroidy ycord)) temp))))
- (setq cnt (1+ cnt))))
-
- (princ "done")
- (terpri)
-
- ;erase construction points.
- (command "ERASE" "w" (getvar "LIMMAX") (getvar "LIMMIN") "")
- ;draw point at centroid
- (command "POINT" (list centroidx centroidy))
- ;restore the original layer setting.
- (command "LAYER" "s" oldlay "")
- (terpri)
- ;print x & y moments
- (princ "X moment = ")(princ momentx)
- (princ " ")
- (princ "Y moment = ")(princ momenty)
- (terpri)
- )
- "No items preselected..select profile and retry")
-
- )
-